﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shsc.Net.FrameWork.Dao.Base;
using System.Reflection;
using System.Collections;

namespace Shsc.Net.FrameWork.Dao.Impl
{
    public class DaoMetaDataImpl : Seasar.Dao.Impl.DaoMetaDataImpl
    {
        protected override void SetupSqlCommand()
        {
            setSqlCommand(_daoInterface, _daoType);
            Type[] baseTypes = _daoInterface.GetInterfaces();
            foreach (Type baseType in baseTypes)
            {
                if (baseType.FullName == typeof(IBaseDao).FullName)
                {
                    setSqlCommand(baseType, baseType);
                }
            }
        }

        private void setSqlCommand(Type interFace, Type daoType)
        {
            MethodInfo[] allMethods = interFace.GetMethods();
            Hashtable names = new Hashtable();
            foreach (MethodInfo mi in allMethods)
            {
                names[mi.Name] = mi;
            }
            IDictionaryEnumerator enu = names.GetEnumerator();
            while (enu.MoveNext())
            {
                try
                {
                    MethodInfo method = daoType.GetMethod((string)enu.Key);
                    if (method.IsAbstract) SetupMethod(method);
                }
                catch (AmbiguousMatchException) { }
            }
        }
    }
}
